package dubbo.server2.impl.controller;

import dubbo.server2.impl.domain.cxf.CxfWebService;
import dubbo.server2.impl.domain.cxf.CxfWebServiceImplService;
import dubbo.server2.impl.domain.cxf.CxfWebServiceRequest;
import dubbo.server2.impl.domain.cxf.CxfWebServiceResponse;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/webservice")
public class WebServiceController {
    private Logger logger = Logger.getLogger(WebServiceController.class);
    @RequestMapping("/cxf2")
    public String cxf2() {
        JaxWsDynamicClientFactory dcf =JaxWsDynamicClientFactory.newInstance();
        org.apache.cxf.endpoint.Client client =dcf.createClient("http://localhost:8084/webservice/cxf?wsdl");
        //getUser 为接口中定义的方法名称  张三为传递的参数   返回一个Object数组
        try {
            Object[] objects = client.invoke("test2","刘彻");
            if(objects==null||objects.length==0)
                return null;
            return objects[0].toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    @RequestMapping("/cxf1")
    public CxfWebServiceResponse cxf1() {
        CxfWebServiceImplService service = new CxfWebServiceImplService();
        CxfWebService cxf = service.getCxfWebServiceImplPort();
        CxfWebServiceRequest request = new CxfWebServiceRequest();
        request.setAge(25);
        request.setName("刘彻");
        return cxf.test1(request);
    }
}
